package com.gamefx.resource
{
	import flash.net.URLStream;
	import com.gamefx.resource.events.LoaderEvent;
	
	internal class LoaderProcess extends URLStream
	{
		public var loader:LoaderItem;

		
		public function LoaderProcess()
		{
			super();
		}
		
		public function process(loader:LoaderItem):void
		{
			this.loader = loader;
			loader.addEventListener(LoaderEvent.CANCEL, loader_cancelHandler, false, 0, true);
			load(loader.request);
		}
		
		override public function close():void
		{
			if (connected)
			{
				super.close();
			}
			loader.removeEventListener(LoaderEvent.CANCEL, loader_cancelHandler);
		}
		
		private function loader_cancelHandler(event:LoaderEvent):void
		{
			close();
		}
	}
}